USE [SistemaDeLeiloes]
GO
/****** Object:  StoredProcedure [dbo].[sp_updLeilao]    Script Date: 26/05/2014 03:33:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Procedure para finalizar leilão após arremate
CREATE PROCEDURE [dbo].[sp_updLeilao]
	@idLeilao INT,
	@idUsuario INT,
	@horaLance DATETIME
AS
BEGIN
	SET NOCOUNT ON;

	UPDATE leiloes
	SET status = 1,
            idUsuario = @idUsuario
	WHERE id = @idLeilao

	INSERT INTO lances (valor,dtCriacao,idUsuario,idLeilao)
	SELECT	valorArremate,
			@horaLance,
			@idUsuario,
			@idLeilao
	FROM leiloes
	WHERE id = @idLeilao

END
